package com.odin.backgrounddownload;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;

public class ByteDataReader
{
    private byte[] data;
    private ByteBuffer buffer;

    public ByteDataReader(byte[] data) {
        this.data = data;
        this.buffer = ByteBuffer.wrap(data);
        this.buffer.order(ByteOrder.LITTLE_ENDIAN);
    }

    public int readInt() {
        return buffer.getInt();
    }

    public String readString() {
        int length = buffer.getInt();
        byte[] stringBytes = new byte[length];
        buffer.get(stringBytes);
        return new String(stringBytes, StandardCharsets.UTF_8);
    }

    public long readLong() {
        return buffer.getLong();
    }
}